#pragma once
#include <QObject>
#include <QVector>


class QTcpSocket;


enum class ActionType : int
{
    kDataNone,
    kDataQueryName,
    kDataQueryNameResult,
    kDataLogin,
    kDataLoginResult,
    kDataGetUserList,
    kDataGetUserListResult,
    kDataMsg,
    kGetDataMsg,
    kCloseConnection,
};

enum class UserMessageType : int
{
    kPlanMsgType,
    kXmlMsgType,
    kPicture,
};

struct UserInfo
{
    QString userName;
};


class ActionBase
{
public:
    ActionBase();
    virtual ~ActionBase();

    ActionType GetType();
    void SetType(ActionType type);

    QString GetErrMsg();
    void SetErrMsg(QString const& errMsg);

    bool IsSuccess();
    void SetSuccess(bool isSuccess);

    void SetSock(QTcpSocket* pSock);
    QTcpSocket* GetSock();

    void InFieldAction(QJsonObject rootObj);
    QJsonObject OutFieldAction();

protected:
    QTcpSocket* m_pSock = nullptr;
    ActionType m_MsgType;
    bool m_IsSuccess;
    QString m_ErrMsg;
};

class LoginAction : public ActionBase
{
public:
    LoginAction();
    ~LoginAction() override;

    QString GetUserName();
    void SetUserName(QString const& userName);

    QString GetToken();
    void SetToken(QString const& token);

    void InFieldAction(QJsonObject rootObj);
    QJsonObject OutFieldAction();

protected:
    QString m_UserName;
    QString m_Token;
};

class UserMessageAction : public LoginAction
{
public:
    UserMessageAction();
    ~UserMessageAction() override;

    UserMessageType GetMessageType();
    void SetMessageType(UserMessageType type);

    void SetPlanMessage(QString const& msg);
    QString GetPlanMessage();

    void InFieldAction(QJsonObject rootObj);
    QJsonObject OutFieldAction();

private:
    QString m_UserMsg;
    UserMessageType m_UserMessageType;
};

class GetUserListAction : public LoginAction
{
public:
    GetUserListAction();
    ~GetUserListAction() override;

    void InFieldAction(QJsonObject rootObj);
    QJsonObject OutFieldAction();

    void SetUserInfoList(QVector<UserInfo> const& userInfoList)
    {
        m_UserInfoList = userInfoList;
    }

    QVector<UserInfo> GetUserInfoList()
    {
        return m_UserInfoList;
    }

protected:
    QString m_Token;
    QVector<UserInfo> m_UserInfoList;
};